package leetCode.q1991;

public class Solution {
    public int pivotIndex(int[] nums) {
        int lenn = nums.length;

        //左侧元素的和
        int left = 0;
        //求右侧元素的和
        int right = 0;
        for(int i=1;i<lenn;i++){
            right+=nums[i];
        }

        //遍历 分割点从0开始
        for(int i=0;i<lenn;i++){
            if(left == right) {return i;}

            if(i == lenn-1){
                return -1;
            } else{
                left+=nums[i];
                right-=nums[i+1];
            }
        }

        return -1;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1,7,3,6,5,6};
        new Solution().pivotIndex(arr);
    }
}